package 力扣._00周赛._430周赛.问题2;

class Solution {
    public String answerString(String word, int numFriends) {
        if(numFriends==1)
            return word;
        // 滑动窗口， 窗口大小范围是[1, word.length()-numFriends+1]
        int l = word.length();
        String maxStr = word.substring(0, 1);
//        System.out.println(l - numFriends + 1);
        for(int windowSize = 1; windowSize <= l - numFriends + 1; windowSize++) {
            System.out.println("windowSize: " + windowSize);
            for (int i = 0; i + windowSize <= l; i++) {
                String subStr = word.substring(i, i + windowSize);
                if (isSLessT(maxStr, subStr)) {
                    maxStr = subStr;
                }
            }
        }
        return maxStr;
    }

    public boolean isSLessT(String s, String t) {
        System.out.println("s: " + s + ", t: " + t);
        int l_s = s.length();
        int l_t = t.length();
        int l = Math.min(l_s, l_t);
        for (int i = 0; i < l; i++) {
            if (s.charAt(i) < t.charAt(i)) {
                return true;
            } else if (s.charAt(i) > t.charAt(i)) {
                return false;
            }
        }
        return l_s < l_t;
    }

    public static void main(String[] args) {
        Solution s = new Solution();
        String word = "gh";
        int numFriends = 1;
        System.out.println(s.answerString(word, numFriends));
    }
}